﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.Devices.Enumeration;
using Windows.Foundation;
using Windows.Graphics.Display;

namespace SharpDepend.WinRT.Classes
{
    public static class Helper
    {
        public static void WaitToComplete(IAsyncInfo handle)
        {
            while (handle.Status != AsyncStatus.Completed && handle.Status != AsyncStatus.Error)
            {

            }
        }

        public static void WaitToComplete(Task handle)
        {
            while (handle.Status != TaskStatus.RanToCompletion && handle.Status != TaskStatus.Faulted)
            {

            }
        }

        /// <summary>
        /// On Windows10 RawPixelsPerViewPixel property will be taken, on Windows8/8.1 ResolutionScale * 0.01 will be taken.
        /// </summary>
        /// <returns></returns>
        public static double GetPixelScale()
        {
            var currentView = DisplayInformation.GetForCurrentView();

            bool ok;
            double win10_RawPixelsPerViewPixel = SharpDepend.Classes.PeformanceHelper.GetProperty<double>(typeof(DisplayInformation), "RawPixelsPerViewPixel", currentView, out ok);
            if (ok)
            {
                // If running on Windows10 take the "RawPixelsPerViewPixel" instead.
                return (float)win10_RawPixelsPerViewPixel;
            }
            else
            {
                // Windows8/RT has not that feature so just take the resolution scale for the mouse. (MainPage.xaml.cs is a bit different)
                return (float)((int)currentView.ResolutionScale * 0.01);
            }
        }
    }
}
